package com.wehotel.weschedule.controller;

import com.wehotel.common.model.R;
import com.wehotel.uni.common.bean.LoginRequestVo;
import com.wehotel.uni.common.query.UserQuery;
import com.wehotel.uni.common.query.UserSearchBean;

import com.wehotel.uni.common.request.PrivilegeRequest;
import com.wehotel.uni.common.view.Pager;
import com.wehotel.uni.common.view.ResultBean;
import com.wehotel.uni.common.view.SingleUserItemVo;
import com.wehotel.uni.common.view.UniResourceNodeLayer;
import com.wehotel.weschedule.constant.C;
import com.wehotel.weschedule.dao.model.PointPublishTask;
import com.wehotel.weschedule.feign.UniUserApi;
import com.wehotel.weschedule.service.MarketingPointService;
import com.wehotel.weschedule.vo.ListPointPublishTaskResp;
import io.swagger.annotations.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.Size;
import java.io.File;
import java.io.IOException;

@Api("xxxx接口")
@RestController
@Validated
@RequestMapping("/marketing_point")
public class MarketingPointContrller {

    @Autowired
    MarketingPointService marketingPointService;

    @Autowired
    UniUserApi uniUserApi;


    @ApiOperation(value = "登陆操作",notes = "使用统一登记的token登陆，登陆后才有权限使用下面接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value = "统一登记的token",paramType = "query"),
    })
    @GetMapping("/login")
    public R login(HttpServletRequest request,String token){



        return R.SUCC;
    }


    @ApiOperation("查询营销积分任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNo",value = "页码，默认值1",defaultValue = "1",paramType = "query"),
            @ApiImplicitParam(name="pageSize",value = "每页记录数，默认值20",defaultValue = "20",paramType = "query"),
            @ApiImplicitParam(name="id",value = "XXXXid",paramType = "query"),
            @ApiImplicitParam(name="name",value = "XXXX名称，模糊匹配",paramType = "query"),
            @ApiImplicitParam(name="creatorName",value = "建立者名称，模糊匹配",paramType = "query"),
            @ApiImplicitParam(name="stime",value = "发放完成时间段起点",paramType = "query"),
            @ApiImplicitParam(name="etime",value = "发放完成时间段终点",paramType = "query"),
            @ApiImplicitParam(name="status",value = "状态，1.草稿 2数据处理中 3待审核 4待发布 5驳回审核 6已发布 7发布失败 8已删除 9发布中 10数据处理异常",paramType = "query"),
    })
    @GetMapping("/list")
    @ResponseBody
    public ListPointPublishTaskResp list(Integer pageNo, Integer pageSize, Integer id, String name
            , String creatorName, Long stime, Long etime, @Range(min=1,max=9) Integer status
            ,@ApiIgnore @SessionAttribute(C.COOKIES_NAME_4_TY_USER) SingleUserItemVo singleUserItemVo
            ,@ApiIgnore @SessionAttribute(C.COOKIES_NAME_4_TY_PRIVILEGE) UniResourceNodeLayer uniResourceNodeLayer ){


        return pointPublishTask;

    }

    @ApiOperation(value = "新增或修改XXXX",notes = "修改时为全量字段修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name="file",value = "文件,修改时可不带文件",paramType = "query"),
            @ApiImplicitParam(name="name",value = "XXXX名称",required = true,paramType = "query"),
            @ApiImplicitParam(name="desc",value = "XXXX描述",required = true,paramType = "query"),
            @ApiImplicitParam(name="lxpOrzxp",value = "积分类型，1为aa积分，2为bb积分",allowableValues = "1,2",required = true,paramType = "query"),
            @ApiImplicitParam(name="id",value = "XXXXid，修改时必填。新增时不送。",paramType = "query"),
            @ApiImplicitParam(name="deliverTime",value = "发放时间",paramType = "query"),

    })
    @PostMapping("/save")
    @ResponseBody
    public R save(MultipartFile file, @Size(max=150) @RequestParam String name, @Size(max=100) @RequestParam String desc
            , @Range(min=1,max=2) @RequestParam Integer lxpOrzxp, @RequestParam(required = false) Integer id
            ,  @RequestParam(required = false) Long deliverTime
            ,@ApiIgnore @SessionAttribute(C.COOKIES_NAME_4_TY_USER) SingleUserItemVo singleUserItemVo

            ){


        return  R.SUCC;
    }

    @ApiOperation("下载xxxx文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "活动id",required = true,paramType = "query"),
            @ApiImplicitParam(name="isResult",value = "是否结果文件，true则下载活动结果文件，false则下载创建者上传文件",allowableValues="true,false",required = true,paramType = "query"),
            })
    @GetMapping("/download")
    public void download(Integer id, Boolean isResult, HttpServletResponse response) throws IOException {

    }



    @ApiOperation("修改XXXX状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "活动id",required = true,paramType = "query"),
            @ApiImplicitParam(name="status",value = "状态，2数据处理中(提交数据处理) 4待发布(审核通过) 5驳回审核",allowableValues = "2,4,5",required = true,paramType = "query"),
            @ApiImplicitParam(name="msg",value = "审核备注",paramType = "query")
    })
    @GetMapping("/updateStatus")
    @ResponseBody
    public R updateStatus(Integer id,Integer status,@Size(max=100) String msg
            ,@ApiIgnore @SessionAttribute(C.COOKIES_NAME_4_TY_USER) SingleUserItemVo singleUserItemVo
            ) throws IOException {

        marketingPointService.updateStatus(id,status,msg,singleUserItemVo,null);

        return R.SUCC;
    }

    @ApiOperation(value = "删除XXXX",notes = "只有没赠送积分的活动能删除，赠送完成或赠送中的活动不能删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "活动id",required = true,paramType = "query"),
    })
    @GetMapping("/del")
    @ResponseBody
    public R del(Integer id,@ApiIgnore @SessionAttribute(C.COOKIES_NAME_4_TY_USER) SingleUserItemVo singleUserItemVo){
        marketingPointService.del(id);
        return R.SUCC;
    }




}
